package cn.chaohi.controller;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;


import cn.chaohi.common.CodeEnum;
import cn.chaohi.controller.model.versionConfig.ConfigAndVersionReq;
import cn.chaohi.controller.model.versionConfig.ConfigAndVersionResp;
import cn.chaohi.model.Result;
import cn.chaohi.service.ConfigAndVersionService;

/**
 * 获取配置信息和版本信息
 * @author James-Yin
 */
@RestController
@RequestMapping("/api/version")
public class VersionController {
	
    @Autowired
    private ConfigAndVersionService configAndVersionService;
    
    private Logger logger = Logger.getLogger(VersionController.class);
    
    /**
     * 购物车获取奖励配置
     * @return
     * @throws Exception 
     */
    @RequestMapping("/checkVersionAndConfig")
    public Result checkVersionAndConfig(@RequestBody ConfigAndVersionReq configAndVersionReq) throws Exception {
    	//logger.info("request parames: " + JSON.toJSONString(configAndVersionReq));
    	
    	//请求参数为空check
    	configAndVersionReq.validate();
    	
    	//配置信息check
    	Result result = configAndVersionService.checkConfigAndVersion(configAndVersionReq);
    	if (null != result) {
    		//logger.info("response body " + JSON.toJSONString(result));
    		return result;
    	}
    	ConfigAndVersionResp configAndVersionResp = configAndVersionService.getConfigAndVersion(configAndVersionReq);
    	//logger.info("response body " + JSON.toJSONString(configAndVersionResp));
        return new Result(CodeEnum.SUCCESS, configAndVersionResp);
    }

}
